﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Kaidou.Model;
using Kaidou.Persister;
using Kaidou.Util;
using Kaidou.Bll;
using System.Collections.Generic;
using System.Globalization;

public partial class seal_seal_report_represen : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoginModel loginModel = (LoginModel)Session["loginModel"];
        if (loginModel == null)
        {
            Response.Redirect("../login.aspx");
        }
        else if (!loginModel.isJimukyoku() && !loginModel.isOperator())
        {
            Response.Redirect("../menu.aspx");
        }

        if (loginModel.isKumiaiin() && sessioncontrol.control())
        {
            Response.Redirect("../control.aspx");
        }

        if (!IsPostBack)
        {
            FAX_RCV_DATE_Y.Text = System.DateTime.Now.ToString("yy");
            FAX_RCV_DATE_M.Text = System.DateTime.Now.ToString("MM");
            FAX_RCV_DATE_D.Text = System.DateTime.Now.ToString("dd");

        }
    }

    protected void submit(object sender, EventArgs e)
    {
        try
        {
            TRN_ReportManager validate = new TRN_ReportManager();
            string juchu_clss = SEAL_ORDER_REPRESEN_JUCHU_CLSS1.Checked ? "20" : "10";
            string rcv_date_y = FAX_RCV_DATE_Y.Text;
            string rcv_date_m = FAX_RCV_DATE_M.Text;
            string rcv_date_d = FAX_RCV_DATE_D.Text;
            string union_code = MST_UNION_CODE.Text;
            string branch_code = MST_BRANCH_CODE.Text;

            List<string> errorCodeList = validate.checkInsertReportRepresen1(juchu_clss, rcv_date_y, rcv_date_m, rcv_date_d, union_code, branch_code, Resources.Resource.ResourceManager);
            msg.Text = ErrorCodeUtil.errorCodeListToHtml(errorCodeList);

            if (errorCodeList.Count == 0)
            {
                CultureInfo culture = new CultureInfo("ja-JP");
                
                // 次の画面用にオブジェクトを用意
                TrnReporth report_h = new TrnReporth();
                report_h.ReportClss = juchu_clss;
                report_h.ReportDate = Convert.ToDateTime((int.Parse(rcv_date_y) + 2000) + "/" + int.Parse(rcv_date_m) + "/" + int.Parse(rcv_date_d), culture);
                report_h.FaxRcvDate = Convert.ToDateTime((int.Parse(rcv_date_y) + 2000) + "/" + int.Parse(rcv_date_m) + "/" + int.Parse(rcv_date_d), culture);
                report_h.ReportYear = rcv_date_y;
                report_h.ReportMonth = rcv_date_m;
                report_h.ReportDay = rcv_date_d;
                report_h.UnionCode = union_code;
                report_h.BranchCode = short.Parse(branch_code);
                Session["CHECKED_REPORT_H"] = report_h;
                Session["represen_unioncode"] = union_code;
                Response.Redirect("seal_report_represen_detail.aspx");
            }
        }
        catch (Exception ex)
        {
            LogManager.error(" seal_seal_report_represen submit "+ex.Message+ex.StackTrace);
        }
    }
}
